﻿using System;



/// <summary>
/// 属性表示类
/// </summary>
[Serializable]
public class SmartProperty : SmartDataBase<float>
{
    public void DoFull()
    {
        Cur = Max;
    }
    public void DoZero()
    {
        Cur = Min;
    }
    public override void DoReset(float max)
    {
        Max = max;
        Cur = Max;
    }
    public float GetScale()
    {
        return Cur / Max;
    }
    public override string ToString()
    {
        return string.Format("{0}/{1}", (int)Cur, (int)Max);
    }
    public virtual bool DoAdd(ref float nValue)
    {
        if (Cur + nValue > Max)
        {
            nValue = Cur + nValue - Max;
            Cur = Max;
            return true;
        }
        if (DoAdd(nValue))
        {
            nValue = 0;
            return true;
        }
        return false;
    }
    public virtual bool DoAdd(float nValue)
    {
        Cur += nValue;
        if (Cur >= Max)
        {
            Cur = Max;
            return true;
        }
        if (Cur < Min)
            Cur = Min;
        return false;
    }

    public bool DoReduce(float nValue)
    {
        Cur -= nValue;
        if (Cur <= Min)
        {
            Cur = Min;
            return true;
        }
        return false;
    }
}

